//
//  JKListViewController.m
//  VistorDemo
//
//  Created by Jack on 2021/8/7.
//

#import "JKListViewController.h"
#import "JKUserManager.h"

static NSString *const OrderListCellId  = @"OrderListCell";
static const NSInteger MaxOrderCount    = 10;

@interface JKListViewController ()<UITableViewDelegate, UITableViewDataSource>{
    NSMutableArray *_orderArray;
}
@property (weak, nonatomic) IBOutlet UITableView *orderList;
@end

@implementation JKListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestOrderData];
    // Do any additional setup after loading the view from its nib.
}

- (void)requestOrderData{
    _orderArray = [[NSMutableArray alloc] initWithCapacity:MaxOrderCount];
    JKUser *user = [[JKUserManager sharedUserManager] currentUser];
    if (!user) {
        return;
    }
    //生成假的order订单
    NSInteger count = [user.userName hash] % MaxOrderCount;
    for (NSInteger index = 0; index < count; index ++) {
        [_orderArray addObject:[NSString stringWithFormat:@"order %@",@(index)]];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_orderArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OrderListCellId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:OrderListCellId];
    }
    cell.textLabel.text = _orderArray[indexPath.row];
    return cell;
}

- (void)dealloc{
    NSLog(@"order list dealloc");
}

@end
